package com.admin.controller;


import com.admin.entity.Academy;
import com.admin.entity.Class;
import com.admin.service.AcademyService;
import com.admin.utils.Result;
import com.admin.vo.query.AcademyQueryVo;
import com.admin.vo.query.ClassQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 * 学院表 前端控制器
 * </p>
 *
 * @author szy
 * @since 2023-03-02
 */
@RestController
@RequestMapping("/api/academy")
public class AcademyController {
    @Resource
    private AcademyService academyService;

    /*
    * 分页查询学院信息
    * */
    @GetMapping("/list")
    public Result list(AcademyQueryVo academyQueryVo){
        IPage<Academy> page = new Page<Academy>(academyQueryVo.getPageNo(), academyQueryVo.getPageSize());
        academyService.getAcademyByPage(page,academyQueryVo);
        return Result.ok(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Academy academy){
        if (academyService.save(academy)){
            return Result.ok().message("学院添加成功");
        }
        return Result.error().message("学院添加失败");
    }

    @PutMapping("/update")
    public Result update(@RequestBody Academy academy){
        if (academyService.updateById(academy)){
            return Result.ok().message("修改学院成功");
        }
        return Result.error().message("修改学院失败");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        if (academyService.removeById(id)){
            return Result.ok().message("学院删除成功");
        }
        return Result.error().message("学院删除失败");
    }
}

